/*
*    Qizx/open 3.0 beta
*
* This code is the open-source version of Qizx.
* Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License 
*  Version 1.1 (the "License"); you may not use this file except in 
*  compliance with the License. You may obtain a copy of the License at
*  http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
*  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
*  for the specific language governing rights and limitations under the
*  License.
*
* The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
*
*/
using System;
namespace System.Qizx.Api {

    /// <summary> Definition of the XQuery Context used for compiling and executing
    /// Expressions. This serves both as Static and Dynamic context (in the sense of
    /// XQuery).
    /// <p>
    /// A XML {@link Library} provides a default XQueryContext which can be
    /// modified. This default context should be suitable for most applications,
    /// with perhaps only a few properties to define, such as base-uri.
    /// <p>
    /// Before an {@link Expression} is compiled, it inherits the context of the
    /// Library from which the expression is created.
    /// <p>
    /// After an Expression is compiled, its XQueryContext reflects declarations
    /// made in the expression itself. The XQuery context can be inspected and
    /// runtime properties modified (mainly the default collation, implicit timezone,
    /// current date).
    /// </summary>
    public struct XQueryContextConstants {
        /// <summary> Value returned by getOrderingMode(): indicates that by default result
        /// sequences must be ordered.
        /// </summary>
        public readonly static int ORDERED = 11;
        /// <summary> Value returned by getOrderingMode(): indicates that by default result
        /// sequences are not required to be ordered.
        /// </summary>
        public readonly static int UNORDERED = 10;
        /// <summary> Value used for properties BoundarySpacePolicy, NamespacePreserveMode,
        /// ConstructionMode, meaning that - respectively - boundary space,
        /// namespaces and schema types should be preserved.
        /// </summary>
        public readonly static int PRESERVE = 21;
        /// <summary> Value used for properties BoundarySpacePolicy, NamespacePreserveMode,
        /// ConstructionMode, meaning that - respectively - boundary space,
        /// namespaces and schema types should not be preserved.
        /// </summary>
        public readonly static int NO_PRESERVE = 20;
        /// <summary> Value used for property NamespaceInheritMode, meaning that namespaces
        /// should be inherited in a node copy operation.
        /// </summary>
        public readonly static int INHERIT = 31;
        /// <summary> Value used for property NamespaceInheritMode, meaning that namespaces
        /// should not be inherited in a node copy operation.
        /// </summary>
        public readonly static int NO_INHERIT = 30;
    }

    public interface XQueryContext {
        /// <summary>
        /// Gets the supported version of XQuery.
        /// </summary>
        /// <value>The X query version.</value>
        /// <returns> a String representing the XQuery version value
        /// </returns>
        string XQueryVersion {
            get;
        }

        /// <summary> Gets the default order for empty sequences in 'order by' clauses.</summary>
        /// <returns> true if the empty sequence or NaN are considered greatest.
        /// </returns>
        /// <summary> Sets the default order for empty sequences in 'order by' clauses.</summary>
        /// <param name="emptyGreatest">true if the empty sequence or NaN are considered
        /// greatest.
        /// </param>
        bool DefaultOrderEmptyGreatest {
            get;
            set;
        }

        /// <summary>
        /// Gets the default inherit part of the copy-namespaces mode.
        /// </summary>
        /// <value>The namespace inherit mode.</value>
        /// <returns> the inherit mode, one of the two values INHERIT or NO_INHERIT
        /// </returns>
        /// <param name="namespaceInheritMode">the inherit mode to set, one of the two
        /// values INHERIT or NO_INHERIT
        /// </param>
        int NamespaceInheritMode {
            get;
            set;
        }

        /// <summary>
        /// Gets the default preserve part of the copy-namespaces mode.
        /// </summary>
        /// <value>The namespace preserve mode.</value>
        /// <returns> the default namespace preserve mode, one of the two values
        /// PRESERVE or NO_PRESERVE.
        /// </returns>
        /// <param name="namespacePreserveMode">the namespace preserve mode to set, one of
        /// the two values PRESERVE or NO_PRESERVE.
        /// </param>
        int NamespacePreserveMode {
            get;
            set;
        }

        /// <summary>
        /// Gets the default boundary space policy for element constructors.
        /// </summary>
        /// <value>The boundary space policy.</value>
        /// <returns> the default boundary space policy, one of the two values
        /// PRESERVE or NO_PRESERVE.
        /// </returns>
        /// <param name="boundarySpacePolicy">the boundary space policy to set, one of the
        /// two values PRESERVE or NO_PRESERVE.
        /// </param>
        int BoundarySpacePolicy {
            get;
            set;
        }

        /// <summary>
        /// Gets the construction mode defined in the static context.
        /// </summary>
        /// <value>The construction mode.</value>
        /// <returns> the default construction mode to set, one of the two values
        /// PRESERVE or NO_PRESERVE.
        /// </returns>
        /// <param name="constructionMode">the construction mode to set, one of the two
        /// values PRESERVE or NO_PRESERVE.
        /// </param>
        int ConstructionMode {
            get;
            set;
        }

        /// <summary>
        /// Gets the URI of the default collation defined in the static context. By
        /// default it is the Unicode codepoints collation.
        /// </summary>
        /// <value>The default collation.</value>
        /// <returns> the defaultCollation
        /// </returns>
        /// <param name="defaultCollation">the URI of the default collation to set
        /// </param>
        /// <throws>  DataModelException if the collation cannot be resolved </throws>
        string DefaultCollation {
            get;

            set;

        }
        /// <summary>
        /// Gets the URI of the default element namespace. By default it is the
        /// blank namespace.
        /// </summary>
        /// <value>The default element namespace.</value>
        /// <returns> the default element namespace
        /// </returns>
        /// <param name="defaultElementNamespace">default element namespace to set
        /// </param>
        string DefaultElementNamespace {
            get;
            set;
        }
        /// <summary>
        /// Gets the URI of the default function namespace. By default it
        /// corresponds to predefined functions (prefix fn:).
        /// </summary>
        /// <value>The default function namespace.</value>
        /// <returns> the URI of the default function namespace, if set, else the
        /// empty string.
        /// </returns>
        /// <param name="defaultFunctionNamespace">the default Function Namespace to set,
        /// may not be null
        /// </param>
        string DefaultFunctionNamespace {
            get;

            set;

        }
        /// <summary>
        /// Gets the default ordering mode for returned sequences.
        /// </summary>
        /// <value>The ordering mode.</value>
        /// <returns> the orderingMode, one of the two values ORDERED or UNORDERED
        /// </returns>
        /// <param name="orderingMode">the ordering mode to set, one of the two values
        /// ORDERED or UNORDERED
        /// </param>
        int OrderingMode {
            get;

            set;

        }

        /// <summary>
        /// Gets or sets the base URI used to resolve relative URIs in expressions.
        /// </summary>
        /// <value>The base URI.</value>
        /// <returns> the base URI, if set, else the empty string. Cannot be null
        /// </returns>
        /// <param name="uri">the base URI, or the empty string. May not be null
        /// </param>
        string BaseURI {
            get;
            set;

        }
        /// <summary>
        /// Returns the prefixes of in-scope namespace definitions. If used on the
        /// context of a compiled Expression,
        /// </summary>
        /// <value>The in scope prefixes.</value>
        /// <returns> String array containing the namespace prefixes. Cannot be null.
        /// </returns>
        System.String[] InScopePrefixes {
            get;

        }
        /// <summary>
        /// Gets the list of global variables declared in the static context.
        /// In the context of an Expression, the variables are those declared in the
        /// expression. In the context of a XQuerySesison (or Library), the
        /// variables can only have been predefined through the method
        /// {@link #declareVariable(QName, SequenceType)}.
        /// </summary>
        /// <value>The variable names.</value>
        /// <returns> array of QNames of the variables. An empty array is returned
        /// when there are no variables.
        /// </returns>
        QName[] VariableNames {
            get;

        }
        /// <summary> Returns the current implicit time-zone in the execution context. By
        /// default it is the system time-zone.
        /// </summary>
        /// <returns> the current implicit time-zone
        /// </returns>
        /// <summary> Defines the implicit time-zone in the execution context.</summary>
        /// <param name="implicitTimeZone">a TimeZone to be used as implicit time-zone
        /// </param>
        System.TimeZone ImplicitTimeZone {
            get;

            set;

        }
        /// <summary> Returns true if a strict compliance with XQuery Specifications is
        /// enforced (not allowing extensions).
        /// </summary>
        /// <returns> true if strict compliance is enforced
        /// </returns>
        /// <seealso cref="setStrictCompliance">
        /// </seealso>
        /// <summary> Sets the strict compliance flag with XQuery Specifications.
        /// <p>
        /// If not enabled (the default), the following extensions are available:
        /// <li>Casting numeric values from/to xs:date, xs:time, xs:dateTime,
        /// xs:dayTimeDuration, xs:yearMonthDuration.
        /// <li>Allow concat() to have a single argument which is a sequence.
        /// </summary>
        /// <param name="strictCompliance">true to enforce strict compliance
        /// </param>
        bool StrictCompliance {
            get;

            set;

        }

        /// <summary>
        /// Gets or sets the specific date/time set by setCurrentDate().
        /// </summary>
        /// <value>The current date.</value>
        /// <returns> the value set by setCurrentDate(), or null by default (use system time)
        /// </returns>
        /// <param name="forcedDate">a date/time, or null to use again the system time.
        /// </param>
        System.DateTime CurrentDate {
            get;
            set;

        }

        /// <summary>
        /// Adds a predefined namespace declaration.
        /// If a namespace with the same prefix already exists, it is replaced.
        /// </summary>
        /// <param name="prefix">namespace prefix to be declared</param>
        /// <param name="namespaceURI">URi of the namespace to be declared</param>
        void DeclarePrefix(string prefix, string namespaceURI);

        /// <summary>
        /// Retrieves the namespace URI associated with a prefix.
        /// </summary>
        /// <param name="prefix">a namespace prefix</param>
        /// <returns>
        /// the namespaceURI associated with the prefix, or null if the
        /// prefix is undefined.
        /// </returns>
        string GetNamespaceURI(string prefix);

        /// <summary>
        /// Returns the type associated with a declared variable.
        /// </summary>
        /// <param name="variableName">qualified name of the variable</param>
        /// <returns>
        /// the type declared for the variable. If the variable is not
        /// declared, returns null.
        /// </returns>
        ISequenceType GetVariableType(QName variableName);

        /// <summary>
        /// Adds a predefined variable declaration.
        /// </summary>
        /// <param name="variableName">qualified name of the variable</param>
        /// <param name="variableType">optional type (may be null) declared for the
        /// variable</param>
        void DeclareVariable(QName variableName, ISequenceType variableType);

#if XBRLFormula
        /// <summary>
        /// extesion for XBRL Formula
        /// </summary>
        /// <param name="optionName"></param>
        /// <param name="value"></param>
        void SetOption(QName optionName, object value);
        /// <summary>
        /// extesion for XBRL Formula
        /// </summary>
        /// <param name="optionName"></param>
        /// <returns></returns>
        object GetOption(QName optionName);
#endif
    }
}